<template>
  <a-popconfirm
    title="确认删除该设备分发记录吗？"
    ok-text="确认"
    class="delete-distribute-message-confirm"
    cancel-text="取消"
    @confirm="confirm"
    @cancel="cancel"
  >
    <a-tag>
      <div class="flex items-center justify-center text-xl">
        <CloseSquareOutlined
          style="color: green"
          class="pb-1 mr-2 text-2xl cursor-pointer"
        />
        <span class="text-green-700"> 删除分发记录 </span>
      </div>
    </a-tag>
  </a-popconfirm>
</template>

<script lang="ts">
import { defineComponent, inject } from "vue";
import { CloseSquareOutlined } from "@ant-design/icons-vue";
import { isString } from "@/utils/typeGuard";
import { useRoute } from "vue-router";
import { undistributeDevice } from "@/controller/Cloud";

export default defineComponent({
  name: "DeleteDistributeMessageConfirm",
  components: {
    CloseSquareOutlined,
  },
  setup() {
    const route = useRoute();
    const refresh: Function = inject("refresh") ?? new Function();
    const confirm = async () => {
      if (isString(route.params.id)) {
        await undistributeDevice(route.params.id);
        refresh();
      }
    };
    const cancel = () => {
      console.log("cancel");
    };
    return { confirm, cancel };
  },
});
</script>

<style scoped lang="scss"></style>
